﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Imaging;
using System.Drawing;

namespace Smith.ImageConverter
{
    public class BMPConvert : BaseConvert, IConvert
    {
        public BMPConvert()
        {
            CodeInfo = GetImageCodeInfo("image/bmp");
            Parameters = new EncoderParameters();
        }

        public override void Save(Bitmap image, string path)
        {
            // draw a white background for png image
            if (image.Tag.Equals(ImageFormat.Png))
            {
                using (Bitmap img = new Bitmap(image.Width, image.Height))
                {
                    using (Graphics g = Graphics.FromImage(img))
                    {
                        g.FillRectangle(Brushes.White, 0, 0, img.Width, img.Height);
                        g.DrawImage(image, 0, 0, image.Width, image.Height);
                        img.Save(path, ImageFormat.Bmp);
                    }
                }
            }
            else
            {
                image.Save(path, ImageFormat.Bmp);
            }
        }
    }
}
